class Solution {
public:
    string compressString(string s)
    {
        string temp;

        for (int lhs = 0, rhs = 0; rhs <= s.size();)
        {
            if (s[lhs] == s[rhs])
            {
                rhs++;
            }
            else
            {
                temp += s[lhs] + to_string(rhs - lhs);
                lhs = rhs;
            }
        }

        return temp.size() < s.size() ? temp : s;
    }
};